<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8"/>
    <title>文件上传组件</title>
    <link rel="stylesheet" type="text/css" href="/site/css/styles.css">
    <link rel="stylesheet" href="/assets/fontawesome-free-5.15.4/css/all.min.css">
</head>
<body>
<div id="app">
    <file-upload :upload-url=""
                 @upload-success="handleAttachFileUpload"
                 @delete-success="handleAttachFileDelete">
    </file-upload>
    <div style="color: #f44336">
        <div v-if="isUpload">
            文件上传成功, 返回文件信息: {{ fileInfo }}
        </div>
        <div v-if="isDelete">
            文件删除成功.
        </div>
    </div>
</div>

<!-- 引入 Vue -->
<script src="/assets/vue/vue3.min.js"></script>
<!-- 引入 Axios -->
<script src="/assets/axios/axios.min.js"></script>
<!-- 引入组件 -->
<script src="/site/js/book/FileUpload.js"></script>
<script>
    const {createApp, ref, onMounted} = Vue;
    const app = {
        // 使用局部注册的方式注册组件
        components: {
            FileUpload
        }
        ,
        setup() {
            const fileInfo = ref({});
            const isUpload = ref(false);
            const isDelete = ref(false);

            // 文件上传成功回调
            const handleAttachFileUpload = (uploadFile) => {
                fileInfo.value = uploadFile;
                isUpload.value = true;
                isDelete.value = false;
            };

            // 文件删除成功回调
            const handleAttachFileDelete = () => {
                isDelete.value = true;
                fileInfo.value = {};
                isUpload.value = false;
            };

            return {fileInfo, isDelete, isUpload, handleAttachFileUpload, handleAttachFileDelete}
        }
    }
    createApp(app).mount('#app');
</script>

</body>
</html>